package dper.study.codes.elasticsearch.api;

import dper.study.codes.elasticsearch.model.CommitModel;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by leichen on 2017/4/19.
 *
 * ElasticsearchRepository 继承 PagingAndSortingRepository, PagingAndSortingRepository提供了分页和排序的支持
 * see http://stackoverflow.com/questions/28897404/spring-data-elasticsearchs-elasticsearchtemplate-vs-elasticsearchrepository
 * simple out of the box, make CRUD operations, index, search and other common operations.
 */
public interface CommitAutoESAPI
        extends ElasticsearchRepository<CommitModel, Integer> {
    /*
        The method name above will be translated into the following Elasticsearch json query
             { "bool" :
                 { "must" :
                     [
                     { "field" : {"commitStrId" : "?"} }
                     ]
                 }
             }
          more see http://docs.spring.io/spring-data/elasticsearch/docs/1.0.0.M1/reference/html/elasticsearch.repositories.html
     */
    List<CommitModel> findByCommitStrId(String commitStrId);

    @Query("{\"bool\" : {\"must\" : {\"field\" : {\"commitStrId\" : \"?0\"}}}}")
    List<CommitModel> findByCommitStrIdAnnotation(String commitStrId) ;

}
